package com.rkc.controller;


import com.rkc.enums.BizCodeEnum;
import com.rkc.request.LockCouponRecordRequest;
import com.rkc.service.CouponRecordService;
import com.rkc.utils.JsonData;
import com.rkc.vo.CouponRecordVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 冉堃赤
 * @since 2021-10-22
 */
@RestController
@RequestMapping("/api/coupon_record/v1")
public class CouponRecordController {

    @Autowired
    private CouponRecordService couponRecordService;

    @GetMapping("page")
    @ApiOperation("分页查询个人优惠券")
    public JsonData page(@ApiParam("当前页") @RequestParam(value = "page", defaultValue = "1", required = false) int page
            , @ApiParam("每页大小") @RequestParam(value = "size", defaultValue = "20", required = false) int size) {
        return JsonData.buildSuccess(couponRecordService.page(page, size));
    }

    @GetMapping("detail/{record_id}")
    @ApiOperation("查询优惠券详情")
    public JsonData getCouponRecordDetail(@ApiParam("记录id") @PathVariable("record_id") long id) {
        CouponRecordVO couponRecordVO = couponRecordService.findById(id);
        return couponRecordVO == null ? JsonData.buildResult(BizCodeEnum.COUPON_NO_EXITS) : JsonData.buildSuccess(couponRecordVO);
    }

    @ApiOperation("RPC-锁定优惠券记录")
    @PostMapping("lock_records")
    public JsonData lockCouponRecords(@ApiParam("锁定优惠券请求对象") @RequestBody LockCouponRecordRequest recordRequest) {
        return couponRecordService.lockCouponRecords(recordRequest);
    }
}

